﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GMS.BIZ
{
    public class Staff
    {
        #region Properties
        private string teacherId;
        public string TeacherId
        {
            get { return teacherId; }
            set { teacherId = value; }
        }
        private string teacherName;
        public string TeacherName
        {
            get { return teacherName; }
            set { teacherName = value; }
        }
        private string teacherGender;
        public string TeacherGender
        {
            get { return teacherGender; }
            set { teacherGender = value; }
        }
        private string teacherOffice;
        public string TeacherOffice
        {
            get { return teacherOffice; }
            set { teacherOffice = value; }
        }
        private string teacherOfficeTel;
        public string TeacherOfficeTel
        {
            get { return teacherOfficeTel; }
            set { teacherOfficeTel = value; }
        }
        private string teacherMobile;
        public string TeacherMobile
        {
            get { return teacherMobile; }
            set { teacherMobile = value; }
        }
        private string teacherMail;
        public string TeacherMail
        {
            get { return teacherMail; }
            set { teacherMail = value; }
        }
        private string teacherAward;
        public string TeacherAward
        {
            get { return teacherAward; }
            set { teacherAward = value; }
        }
        private string teacherField;
        public string TeacherField
        {
            get { return teacherField; }
            set { teacherField = value; }
        }
        private string teacherTitle;
        public string TeacherTitle
        {
            get { return teacherTitle; }
            set { teacherTitle = value; }
        }
        private bool ifTeacher;
        public bool IfTeacher
        {
            get { return ifTeacher; }
            set { ifTeacher = value; }
        }
        private bool ifClassTeacher;
        public bool IfClassTeacher
        {
            get { return ifClassTeacher; }
            set { ifClassTeacher = value; }
        }
        #endregion Properties

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="teacherID">教师工号</param>
        public Staff(string teacherID)
        {
            this.teacherId = teacherID;
            this.GetStaffInfomation();
        }

        /// <summary>
        /// 空构造
        /// </summary>
        public Staff()
        { }

        public void GetStaffInfomation()
        {
            string teacherID = this.teacherId;

            GMS.ORM.Model.UTeacher myUTeacher = new GMS.ORM.Model.UTeacher();
            GMS.ORM.DAL.UTeacher optUTeacher = new GMS.ORM.DAL.UTeacher();
            myUTeacher = optUTeacher.GetModel(teacherID);

            this.teacherId = myUTeacher.tch_id;
            this.teacherName = myUTeacher.tch_name;
            this.teacherGender = myUTeacher.tch_gender;
            this.teacherOffice = myUTeacher.tch_office;
            this.teacherOfficeTel = myUTeacher.tch_office_tel;
            this.teacherMobile = myUTeacher.tch_mobile;
            this.teacherMail = myUTeacher.tch_mail;
            this.teacherAward = myUTeacher.tch_award;
            this.teacherField = myUTeacher.tch_field;
            this.teacherTitle = myUTeacher.tch_title;
            this.ifTeacher = (myUTeacher.if_teacher == 0) ? false : true;
            this.ifClassTeacher = (myUTeacher.if_classteacher == 0) ? false : true;
        }

        /// <summary>
        /// 修改个人信息
        /// </summary>
        public string PersonalInfomationEdit()
        {
            GMS.ORM.Model.UTeacher myUTeacher = new GMS.ORM.Model.UTeacher();
            myUTeacher.tch_id = this.teacherId;
            myUTeacher.tch_name = this.teacherName;
            myUTeacher.tch_gender = this.teacherGender;
            myUTeacher.tch_office = this.teacherOffice;
            myUTeacher.tch_office_tel = this.teacherOfficeTel;
            myUTeacher.tch_mobile = this.teacherMobile;
            myUTeacher.tch_mail = this.teacherMail;
            myUTeacher.tch_award = this.teacherAward;
            myUTeacher.tch_field = this.teacherField;
            myUTeacher.tch_title = this.teacherTitle;
            myUTeacher.if_teacher = this.ifTeacher ? 1 : 0;
            myUTeacher.if_classteacher = this.ifClassTeacher ? 1 : 0;

            GMS.ORM.DAL.UTeacher optUTeacher = new GMS.ORM.DAL.UTeacher();
            bool ok = optUTeacher.Update(myUTeacher);

            if (!ok) return GMS.BIZ.ErrorMessage.DBOptError;
            else return GMS.BIZ.ErrorMessage.OK;
            
        }

        /// <summary>
        /// 获得教师姓名
        /// </summary>
        /// <param name="teacherID">教师工号</param>
        static public string GetName(string teacherID)
        {
            GMS.ORM.DAL.UTeacher optUTeacher = new GMS.ORM.DAL.UTeacher();
            if (optUTeacher.Exists(teacherID) == false)
                return ErrorMessage.NoSuchData;
            else return optUTeacher.GetModel(teacherID).tch_name;
        }

        /// <summary>
        /// 获得教师ID
        /// </summary>
        /// <param name="tchname">教师姓名</param>
        /// <returns>教师ID</returns>
        static public string GetTchId(string tchname)
        {
            GMS.ORM.DAL.UTeacher optUTeacher = new GMS.ORM.DAL.UTeacher();
            DataSet myDs = optUTeacher.GetList("tch_name='" + tchname + "'");
            if (myDs.Tables[0].Rows.Count == 0) return ErrorMessage.NoSuchData;
            return myDs.Tables[0].Rows[0]["tch_id"].ToString();
        }

        static public DataSet GetAllStaff()
        {
            GMS.ORM.DAL.UTeacher optUTeacher = new GMS.ORM.DAL.UTeacher();
            return optUTeacher.GetList("1=1");

        }
    }
}
